function getProxyOnUIThread(aObject, aInterface) {
    var eventQSvc = Components.
            classes["@mozilla.org/event-queue-service;1"].
            getService(Components.interfaces.nsIEventQueueService);

    var uiQueue = eventQSvc.
            getSpecialEventQueue(Components.interfaces.
            nsIEventQueueService.UI_THREAD_EVENT_QUEUE);

    var proxyMgr = Components.
            classes["@mozilla.org/xpcomproxy;1"].
            getService(Components.interfaces.nsIProxyObjectManager);

    return proxyMgr.getProxyForObject(uiQueue,
            aInterface, aObject, 5);
    // 5 == PROXY_ALWAYS | PROXY_SYNC
}

function initialiserLDAP(pDn, pHost) {

	jsdump("Getting proxy on ConnectionLDAPMessageListener");

	var proxy = getProxyOnUIThread(new ConnectionLDAPMessageListener, Components.interfaces.nsILDAPMessageListener);
	
	jsdump("Initializing LDAP connection on "+pHost+" as DN: "+pDn+".");

	gLdapConn.init(pHost, 389, false, pDn, proxy, null, gLdapConn.VERSION3);
}


